/**
* Copyright 2009, Jethro Grassie, Creative Jar Technology Ltd (http://www.cjtech.co.uk)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
**/

package com.cjt.rmi.server;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Date;

import com.cjt.rmi.common.ITimeUtil;

public class TimeUtil implements ITimeUtil
{
    public TimeUtil()
    {
        super();
    }

    public String getTime() throws RemoteException
    {
        return (new Date()).toString();
    }


    public static void main(String[] args)
    {
        if(System.getSecurityManager() == null)
        {
            System.setSecurityManager(new SecurityManager());
        }
        try
        {
            String name = "TimeUtil";
            TimeUtil impl = new TimeUtil();
            ITimeUtil stub = (ITimeUtil) UnicastRemoteObject.exportObject(impl, 0);
            Registry registry = LocateRegistry.getRegistry();
            registry.rebind(name, stub);
            System.out.println("TimeUtil bound");
        }
        catch(Exception e)
        {
            System.err.println("TimeUtil exception:");
            e.printStackTrace();
        }
    }

}

